<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>genshi.path.Path</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="genshi-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="genshi-module.html">Package&nbsp;genshi</a> ::
        <a href="genshi.path-module.html">Module&nbsp;path</a> ::
        Class&nbsp;Path
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class Path</h1><p class="nomargin-top"></p>
<pre class="base-tree">
object --+
         |
        <strong class="uidshort">Path</strong>
</pre>

<hr />
<p>Implements basic XPath support on streams.</p>
<p>Instances of this class represent a &quot;compiled&quot; XPath expression, and provide
methods for testing the path against a stream, as well as extracting a
substream matching that path.</p>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Instance Methods</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="genshi.path.Path-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">text</span>,
        <span class="summary-sig-arg">filename</span>=<span class="summary-sig-default">None</span>,
        <span class="summary-sig-arg">lineno</span>=<span class="summary-sig-default">-1</span>)</span><br />
      Create the path object from a string.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="genshi.path.Path-class.html#__repr__" class="summary-sig-name">__repr__</a>(<span class="summary-sig-arg">self</span>)</span><br />
      repr(x)</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><a href="genshi.core.Stream-class.html" class="link">Stream</a></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="genshi.path.Path-class.html#select" class="summary-sig-name">select</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">stream</span>,
        <span class="summary-sig-arg">namespaces</span>=<span class="summary-sig-default">None</span>,
        <span class="summary-sig-arg">variables</span>=<span class="summary-sig-default">None</span>)</span><br />
      Returns a substream of the given stream that matches the path.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><tt class="rst-docutils literal"><span class="pre">function</span></tt></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="genshi.path.Path-class.html#test" class="summary-sig-name">test</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">ignore_context</span>=<span class="summary-sig-default">False</span>)</span><br />
      Returns a function that can be used to track whether the path matches
a specific stream event.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__getattribute__</code>,
      <code>__hash__</code>,
      <code>__new__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__setattr__</code>,
      <code>__str__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Properties</span></td>
</tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Method Details</span></td>
</tr>
</table>
<a name="__init__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">text</span>,
        <span class="sig-arg">filename</span>=<span class="sig-default">None</span>,
        <span class="sig-arg">lineno</span>=<span class="sig-default">-1</span>)</span>
    <br /><em class="fname">(Constructor)</em>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  Create the path object from a string.
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>text</code></strong> - the path expression</li>
        <li><strong class="pname"><code>filename</code></strong> - the name of the file in which the path expression was
found (used in error messages)</li>
        <li><strong class="pname"><code>lineno</code></strong> - the line on which the expression was found</li>
    </ul></dd>
    <dt>Overrides:
        object.__init__
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="__repr__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__repr__</span>(<span class="sig-arg">self</span>)</span>
    <br /><em class="fname">(Representation operator)</em>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  repr(x)
  <dl class="fields">
    <dt>Overrides:
        object.__repr__
        <dd><em class="note">(inherited documentation)</em></dd>
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="select"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">select</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">stream</span>,
        <span class="sig-arg">namespaces</span>=<span class="sig-default">None</span>,
        <span class="sig-arg">variables</span>=<span class="sig-default">None</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>Returns a substream of the given stream that matches the path.</p>
<p>If there are no matches, this method returns an empty stream.</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">from</span> genshi.input <span class="py-keyword">import</span> XML
<span class="py-prompt">&gt;&gt;&gt; </span>xml = XML(<span class="py-string">'&lt;root&gt;&lt;elem&gt;&lt;child&gt;Text&lt;/child&gt;&lt;/elem&gt;&lt;/root&gt;'</span>)</pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">print</span> Path(<span class="py-string">'.//child'</span>).select(xml)
<span class="py-output">&lt;child&gt;Text&lt;/child&gt;</span></pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">print</span> Path(<span class="py-string">'.//child/text()'</span>).select(xml)
<span class="py-output">Text</span></pre>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>stream</code></strong> - the stream to select from</li>
        <li><strong class="pname"><code>namespaces</code></strong> - (optional) a mapping of namespace prefixes to URIs</li>
        <li><strong class="pname"><code>variables</code></strong> - (optional) a mapping of variable names to values</li>
    </ul></dd>
    <dt>Returns: <a href="genshi.core.Stream-class.html" class="link">Stream</a></dt>
        <dd>the substream matching the path, or an empty stream</dd>
  </dl>
</td></tr></table>
</div>
<a name="test"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">test</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">ignore_context</span>=<span class="sig-default">False</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>Returns a function that can be used to track whether the path matches
a specific stream event.</p>
<p>The function returned expects the positional arguments <tt class="rst-docutils literal"><span class="pre">event</span></tt>,
<tt class="rst-docutils literal"><span class="pre">namespaces</span></tt> and <tt class="rst-docutils literal"><span class="pre">variables</span></tt>. The first is a stream event, while the
latter two are a mapping of namespace prefixes to URIs, and a mapping
of variable names to values, respectively. In addition, the function
accepts an <tt class="rst-docutils literal"><span class="pre">updateonly</span></tt> keyword argument that default to <tt class="rst-docutils literal"><span class="pre">False</span></tt>. If
it is set to <tt class="rst-docutils literal"><span class="pre">True</span></tt>, the function only updates its internal state,
but does not perform any tests or return a result.</p>
<p>If the path matches the event, the function returns the match (for
example, a START or TEXT event.) Otherwise, it returns <tt class="rst-docutils literal"><span class="pre">None</span></tt>.</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">from</span> genshi.input <span class="py-keyword">import</span> XML
<span class="py-prompt">&gt;&gt;&gt; </span>xml = XML(<span class="py-string">'&lt;root&gt;&lt;elem&gt;&lt;child id=&quot;1&quot;/&gt;&lt;/elem&gt;&lt;child id=&quot;2&quot;/&gt;&lt;/root&gt;'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>test = Path(<span class="py-string">'child'</span>).test()
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> event <span class="py-keyword">in</span> xml:
<span class="py-more">... </span>    <span class="py-keyword">if</span> test(event, {}, {}):
<span class="py-more">... </span>        <span class="py-keyword">print</span> event[0], repr(event[1])
<span class="py-output">START (QName(u'child'), Attrs([(QName(u'id'), u'2')]))</span></pre>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>ignore_context</code></strong> - if <code class="link">True</code>, the path is interpreted like a pattern
in XSLT, meaning for example that it will match
at any depth</li>
    </ul></dd>
    <dt>Returns: <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">function</span></tt></dt>
        <dd>a function that can be used to test individual events in a
stream against the path</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="genshi-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Wed Jul  9 18:16:21 2008
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
